package com.maybach.common.enums;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by houenxun on 16/1/18.
 */
public enum PartnerTypeEnum {
    dealer(1, "经销商"),
    provider(2, "供应商"),
    dealerAndProvider(3, "即使供应商又是经销商");

    private int code;
    private String desc;


    private PartnerTypeEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }


    public int getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    /**
     * 根据状态code 获取状态值
     *
     * @param code
     * @return
     */
    public static PartnerTypeEnum getStatus(int code) {
        for (PartnerTypeEnum status : PartnerTypeEnum.values()) {
            if (code == status.code) {
                return status;
            }
        }
        return null;
    }

    /**
     * 根据状态code 获取状态列表
     *
     * @param code
     * @return
     */
    public static List<PartnerTypeEnum> getStatusList(int code) {
        List<PartnerTypeEnum> list = new ArrayList<PartnerTypeEnum>();
        for (PartnerTypeEnum status : PartnerTypeEnum.values()) {
            if ((code & status.code) == status.code) {
                list.add(status);
            }
        }
        return list;
    }
}
